from tw.forms.validators import Int, NotEmpty,UnicodeString,All,ForEach,DateConverter
from tw.forms.fields import TableForm,TextField, TextArea, CheckBox, HiddenField, RadioButtonList,SingleSelectField
from tw.forms import CalendarDatePicker,validators
from tw.dynforms import HidingTableFieldSet,HidingRadioButtonList,HidingTableForm
from add_metadata import NakedDateConverter
from tw.api import Widget,WidgetsList
from tg import url
import tw.dynforms as twd
from lifepyscle.controllers.common import MAX_RECUR,choice_reminder_days
from formencode.schema import Schema

class Schmarri(HidingTableFieldSet):
    children = [
        HidingRadioButtonList("Bll",label_text='Contact method', options=('E-mail', 'Phone', 'SMS'),
            mapping={
                0: ['email_address'],\
                1: ['phone_number'],\
                2: ['sms'],\
            }),
        TextField(name='email_address',label_text='Email',id='email_address'),
        TextField(name='phone_number',label_text='Phone',id='phone_number'),
        TextField(name='sms',label_text='SMS',id='sms'),
    ]


class DocFormFields(WidgetsList):
    """ Widget to add/edit document's metadata
        - signatories (single text field, comma separated)
        - tags (single text field, comma separated)
        - freetext (choice of file or text field)
    """
    doc_id = HiddenField(id="doc_id")
    sigs = TextField(id='sigs',label_text='Signatories',help_text='Comma separated list of signatories',attrs=dict(style="width:90%"))
    tags = TextArea(id='tags',label_text='Tags',help_text='Comma separated list of tags',attrs=dict(style="width:90%"))
    schmarri = Schmarri()
doc_form = HidingTableForm(id="doc_form",
                    hover_help = True,
                    fields=DocFormFields(),
                    action="/doc/update")
